class Assignment < Event
  belongs_to :user
  belongs_to :course
  has_many :assignment_answers, :dependent => :destroy
  has_one :event_blob, :foreign_key => 'event_id', :dependent => :destroy

  validates_presence_of :course

  def average
    return @average if not @average.nil?
    sum = 0
    count = 0
    assignment_answers.each do |answer|
      sum +=answer
      count+=1
    end
    @average = sum / count
    @average
  end

  def missing_users
    total_users = course.users.size
    total_users - assignment_answers.size
  end

  def has_ungraded_answers?
    for ans in assignment_answers
      return true if ans.graded.nil?
    end
    return false
  end
end
